package com.example.everying.mapper.content;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.everying.model.entity.content.ActivityArticle;
import com.example.everying.model.vo.content.ActivityArticleVo;
import com.example.everying.model.vo.content.ApplyViewVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ActivityArticleMapper extends BaseMapper<ActivityArticle> {
    /**
     * 分页查询
     *
     * @param page
     * @param vo
     * @return
     */
    Page<ActivityArticleVo> selectPageWithUser(Page<ActivityArticleVo> page, ActivityArticleVo vo);

    // 在 ActivityArticleMapper 接口中添加新方法
Page<ActivityArticleVo> selectPageWithUserAndLocation(Page<ActivityArticleVo> pageParam,
                                                     ActivityArticleVo vo,
                                                     double searchLng,
                                                     double searchLat,
                                                     double filterRange);


    ActivityArticleVo articleId(String articleId);

    /**
     * 参与记录
     *
     * @param userId
     * @return
     */
    IPage<ActivityArticleVo> parSelect(Page<ActivityArticleVo> pageParam, @Param("userId") String userId, String tokenId, String status);

    /**
     * 发布记录
     *
     * @param userId
     * @param tokenId
     * @return
     */
    IPage<ActivityArticleVo> publishSelect(Page<ActivityArticleVo> pageParam, @Param("userId") String userId, String tokenId, String status);

    ActivityArticle getArticleById(String id);

    /**
     * 注销用户的文章更改为失效状态
     *
     * @param userId
     */
    void updateByUserID(String userId);

    Boolean updateEndTimeById(@Param("endTime") LocalDateTime endTime);
    // 执行批量更新
    int updateEndTimeById(@Param("ids") List<String> ids);
    List<ActivityArticle> selectArticleIdsForUpdate(@Param("userId") String userId,@Param("endTime") LocalDateTime endTime);

    /**
     * 只传userId查看共同的单子,只传userId查看共同的单子,userId和status两个都传是查看别人未开始的单子
     * @param pageParam
     * @param userId
     * @param status
     * @param id
     * @return
     */
    IPage<ActivityArticleVo> selectByUser(Page<ActivityArticleVo> pageParam, String userId ,String status, @Param("id") String id);

    List<ApplyViewVo> selectArtUserId(@Param("userId") String userId);

    List<ApplyViewVo> selectAppUserId(@Param("userId") String userId);

    /**
     * 待确认列表查询
     *
     * @param pageParam
     * @param userId
     * @param tokenId
     * @return
     */
    IPage<ActivityArticleVo> selectStatus(Page<ActivityArticleVo> pageParam, String userId, String appId, String tokenId);

    /**
     * 申诉列表查询
     *
     * @param pageParam
     * @param userId
     * @param tokenId
     * @return
     */
    IPage<ActivityArticleVo> selectAppealStatus(Page<ActivityArticleVo> pageParam, String userId,String appId, String tokenId);

    /**
     * 查询用户当天发布的第一条悬赏帖子
     * @param userId
     * @return
     */
    ActivityArticle getFirstRewardPostToday(String userId);
}
